
<script type="text/javascript">


    $.validator.setDefaults({
        submitHandler: function() {
            $.post("<?= site_url() ?>setup/update_area", {
                idarea: $('#idarea').val(),
                area: $('#area').val(),
                regional: $('#regional').val(),
                officename: $('#officename').val(),
                address: $('#address').val(),
                status: $('#status').val(),
                type: $('#type').val()
            },
            function(data) {
                window.location = '<?php echo base_url(); ?>setup/area';
            });
        }
    });
    $(document).ready(function() {

        $("#formarea").keypress(function(e) {
            if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
                $.validator.setDefaults({
                    submitHandler: function() {
                        $.post("<?= site_url() ?>setup/update_area", {
                            idarea: $('#idarea').val(),
                            area: $('#area').val(),
                            regional: $('#regional').val(),
                            officename: $('#officename').val(),
                            address: $('#address').val(),
                            status: $('#status').val(),
                            type: $('#type').val()
                        },
                        function(data) {
                            window.location = '<?php echo base_url(); ?>setup/area';
                        });
                    }
                });
            }
        });

        $("#formarea").validate();

//        $('#type').select2({
//            placeholder: "Select Type",
//            allowClear: true
//        });
//        $('#status').select2({
//            placeholder: "Select Status",
//            allowClear: true
//        });
    });

    function cancel() {
        $.post("<?= site_url() ?>setup/area", function(data) {
            window.location = '<?php echo base_url(); ?>setup/area';
        });
    }

</script>

<form class="form-horizontal" id="formarea" role="form" method="post" action="#">
    <div class="col-md-offset-1">
        <div class="col-md-11">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h4 class="panel-title"><b class="caret"></b><b> Form - Edit Area</b></h4>
                </div>
                <div class="panel-body">

                    <?php if (isset($detil_data) && !empty($detil_data)) { ?>
                        <div class="col-sm-8">
                            <div class="col-sm-4"><label for="area" class="control-label">Area<span style="color:red;">*</span></label></div>
                            <div class="col-sm-5"><input type="text" class="form-control input-sm required" id="area" name="area" value="<?php echo $detil_data['AREA_NAME']; ?>"></div>
                        </div>
                        <div class="col-sm-8">
                            <div class="col-sm-4"><label for="regional" class="control-label">Regional<span style="color:red;">*</span></label></div>
                            <div class="col-sm-7"><input type="text" class="form-control input-sm required" id="regional" name="regional" value="<?php echo $detil_data['AREA_DESC']; ?>"></div>
                        </div>
                        <div class="col-sm-8">
                            <div class="col-sm-4"><label for="officename" class="control-label">Office Name<span style="color:red;">*</span></label></div>
                            <div class="col-sm-8"><input type="text" class="form-control input-sm required" id="officename" name="officename" value="<?php echo $detil_data['REGIONAL_NAME']; ?>"></div>
                        </div>
                        <div class="col-sm-8">
                            <div class="col-sm-4"><label for="address" class="control-label">Address<span style="color:red;">*</span></label></div>
                            <div class="col-sm-8">
                                <textarea id="address" name="address" row="6" cols="50" class="form-control required"><?php echo $detil_data['REGIONAL_ADDRESS']; ?></textarea>
                            </div>
                        </div>
                        <div class="col-sm-8">
                            <div class="col-sm-4"><label for="type" class="control-label">Type<span style="color:red;">*</span></label></div>
                            <div class="col-sm-5">
                                <select name="type" id="type" class="form-control required select2">
                                    <option value="">-- select --</option>
                                    <option value="Y"<?php echo (strtoupper($detil_data['ISDOMESTIC']) == 'Y') ? 'selected' : ''; ?>>Domestik</option>
                                    <option value="N"<?php echo (strtoupper($detil_data['ISDOMESTIC']) != 'Y') ? 'selected' : ''; ?>>Internasional</option>
                                </select>
                            </div>
                        </div>
                        <div class="col-sm-8">
                            <div class="col-sm-4"><label for="status" class="control-label">Status<span style="color:red;">*</span></label></div>
                            <div class="col-sm-5">
                                <select name="status" id="status" class="form-control required select2">
                                    <option value="">-- select --</option>
                                    <option value="Y"<?php echo (strtoupper($detil_data['AREA_STATUS']) == 'Y') ? 'selected' : ''; ?>>Active</option>
                                    <option value="N"<?php echo (strtoupper($detil_data['AREA_STATUS']) != 'Y') ? 'selected' : ''; ?>>Non Active</option>
                                </select>
                            </div>
                        </div>		
                        <div class="col-sm-8" style="padding-bottom: 20px;">
                            <div class="col-sm-4">
                                &nbsp;
                            </div>
                        </div>
                        <div class="col-sm-8">
                            <div class="col-sm-4"><label for="button" class="control-label">&nbsp;</label></div>
                            <div class="col-sm-4">
                                <input type="hidden" id="idarea" name="idarea" value="<?php echo $detil_data['AREA_ID']; ?>" />
                                <button type="submit" class="btn btn-success btn-block">Save Edit</button>
                            </div>
                            <div class="col-sm-4">
                                <button type="button" class="btn btn-default btn-block" onclick="cancel();" >Cancel</button>
                            </div>
                        </div>
                    <?php } //end if ?>

                </div>
            </div>
        </div>
    </div>
</form>	

<div style="margin-top:20px;"></div>

